﻿//#region Description
///*  File Name:      MEBasePrimitive.cs
// *  Author:         Adam Goodchild
// *  
// *  Description:    This is a Base Primitive Class.
// *                  Stores common data between all Primitive Shapes.
// *                  All Primitives are dervied from this class.
//*/
//#endregion

//#region Using Statements
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using Microsoft.Xna.Framework;
//using Microsoft.Xna.Framework.Graphics;
//using MinimizeEngine.Managers;
//#endregion

//namespace MinimizeEngine.Entities.Primitives
//{
//    public abstract class MEBasePrimitive : IDisposable
//    {
//        #region Fields

//        /// <summary>
//        /// Index Data
//        /// </summary>
//        private List<ushort> mIndices = new List<ushort>();

//        /// <summary>
//        /// Vertex Data
//        /// </summary>
//        private List<VertexPositionNormal> mVertices = new List<VertexPositionNormal>();

//        /// <summary>
//        /// Vertex Declaration
//        /// </summary>
//        private VertexDeclaration mVertexDeclaration;

//        /// <summary>
//        /// Vertex Buffer
//        /// </summary>
//        private VertexBuffer mVertexBuffer;

//        /// <summary>
//        /// Index Buffer
//        /// </summary>
//        private IndexBuffer mIndexBuffer;

//        #endregion

//        #region Properties

//        /// <summary>
//        /// The Primitive Shapes Vertex Declaration
//        /// </summary>
//        public VertexDeclaration VertexDeclaration
//        {
//            get { return mVertexDeclaration; }
//        }

//        /// <summary>
//        /// The Primitive Shapes Vertex Buffer
//        /// </summary>
//        public VertexBuffer VertexBuffer
//        {
//            get { return mVertexBuffer; }
//        }

//        /// <summary>
//        /// The Primitive Shapes Vertices
//        /// </summary>
//        public List<VertexPositionNormal> Vertices
//        {
//            get { return mVertices; }
//        }

//        /// <summary>
//        /// The Primitive Shapes Index Buffer
//        /// </summary>
//        public IndexBuffer IndexBuffer
//        {
//            get { return mIndexBuffer; }
//        }

//        /// <summary>
//        /// The Primitive Shapes Indices
//        /// </summary>
//        public List<ushort> Indices
//        {
//            get { return mIndices; }
//        }

//        /// <summary>
//        /// Add a new Vertex to the Primitive Shape.
//        /// Should only be called during the Initialization process.
//        /// </summary>
//        /// <param name="position"></param>
//        /// <param name="normal"></param>
//        protected void AddVertex(Vector3 position, Vector3 normal)
//        {
//            mVertices.Add(new VertexPositionNormal(position, normal));
//        }

//        /// <summary>
//        /// Add a new Index to the Primitive Shape.
//        /// Should only be called during the Initialization process.
//        /// </summary>
//        protected void AddIndex(int index)
//        {
//            if(index > ushort.MaxValue)
//            {
//                throw new ArgumentOutOfRangeException("index");
//            }

//            mIndices.Add((ushort)index);
//        }

//        /// <summary>
//        /// Current Vertex Count
//        /// </summary>
//        protected int CurrentVertexCount
//        {
//            get { return mVertices.Count; }
//        }

//        #endregion

//        #region Initialization

//        ~MEBasePrimitive()
//        {
//            Dispose(false);
//        }

//        protected void Initialize()
//        {
//            //Create new Vertex Declaration
//            mVertexDeclaration = new VertexDeclaration(MEEngineManager.DeviceManager.GraphicsDevice, VertexPositionNormal.VertexElements);

//            //Create a new Vertex Buffer, and copy the Vertex Data into it
//            mVertexBuffer = new VertexBuffer(MEEngineManager.DeviceManager.GraphicsDevice, typeof(VertexPositionNormal), mVertices.Count, BufferUsage.None);
//            mVertexBuffer.SetData(mVertices.ToArray());

//            //Create an Index Buffer, and copy the Index Data into it
//            mIndexBuffer = new IndexBuffer(MEEngineManager.DeviceManager.GraphicsDevice, typeof(ushort), mIndices.Count, BufferUsage.None);
//            mIndexBuffer.SetData(mIndices.ToArray());
//        }

//        #endregion

//        #region IDisposable Members

//        public void Dispose()
//        {
//            Dispose(true);
//            GC.SuppressFinalize(this);
//        }

//        /// <summary>
//        /// Free up the Resources used by the Primitive Shape
//        /// </summary>
//        /// <param name="isDisposing"></param>
//        protected virtual void Dispose(bool isDisposing)
//        {
//            if(isDisposing)
//            {
//                if (mVertexDeclaration != null)
//                    mVertexDeclaration.Dispose();

//                if (mVertexBuffer != null)
//                    mVertexBuffer.Dispose();

//                if (mIndexBuffer != null)
//                    mIndexBuffer.Dispose();
//            }
//        }

//        #endregion
//    }

//    #region VertexPositionNormal Struct
//    /// <summary>
//    /// This is a custom Vertex Type for any Vertices that do not have 
//    /// Texture Coordinates, but just a Position and a Normal.
//    /// </summary>
//    public struct VertexPositionNormal
//    {
//        #region Fields

//        public Vector3 mPosition;
//        public Vector3 mNormal;

//        /// <summary>
//        /// Size of the Vertex Type in Bytes
//        /// </summary>
//        public const int mSizeInBytes = 24;

//        #endregion

//        #region Properties

//        /// <summary>
//        /// Vertex Information. Used for the creation of a VertexDeclaration
//        /// </summary>
//        public static readonly VertexElement[] VertexElements =
//        {
//            new VertexElement(0, 0, VertexElementFormat.Vector3,
//                                    VertexElementMethod.Default,
//                                    VertexElementUsage.Position, 0),

//            new VertexElement(0, 12, VertexElementFormat.Vector3,
//                                     VertexElementMethod.Default,
//                                     VertexElementUsage.Normal, 0),
//        };

//        #endregion

//        #region Initialization

//        /// <summary>
//        /// Construct a new VertexPositionNormal
//        /// </summary>
//        /// <param name="position"></param>
//        /// <param name="normal"></param>
//        public VertexPositionNormal(Vector3 position, Vector3 normal)
//        {
//            mPosition = position;
//            mNormal = normal;
//        }

//        #endregion
//    }
//    #endregion
//}
